package com.v5ba.demo.test;

import cn.hutool.json.JSONUtil;
import org.springframework.cglib.beans.BeanGenerator;
import org.springframework.cglib.beans.BeanMap;

import java.lang.reflect.Field;

/**
 * @author yiren
 * @since 2022/7/25
 */
public class T {
    public static void main(String[] args) throws IllegalAccessException {
        BeanGenerator generator = new BeanGenerator();
        generator.addProperty("name", String.class);
        generator.addProperty("age", Integer.class);
        generator.addProperty("price", Long.class);
        Object obj = generator.create();
        BeanMap beanMap = BeanMap.create(obj);
        beanMap.put("name", "张三");
        System.out.println(JSONUtil.toJsonStr(obj));

        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field f: fields) {
            f.setAccessible(true);
            System.out.println("field: " + f.getName() + " = " + f.get(obj));
        }
    }
}
